#include "bitset.h"
#include <string>

namespace BLZ
{
    template <size_t K, size_t M, size_t N>
    class BloomFilter
    {
        private:
            BLZ::bitset<M> _bs;
            
            size_t StrToHash(std::string str)    
            {    
                unsigned int seed = 131;    
                size_t hash = 0;    
                for(auto c : str)    
                {    
                    hash = (hash * seed) + static_cast<unsigned int>(c);    
                }    
                return hash;                  
            } 
        public:
            size_t HashFunc(int a, int x)
            {
                return (((a * x + a + 1) % ((1 << 61) - 1)) % M);
            }
            void set(std::string str)
            {
                int i = 0;
                for(i = 1; i <= K; i++)
                {
                    _bs.set(HashFunc(i, StrToHash(str)));
                } 
            }
            bool test(std::string str)
            {
                int i = 0;
                for(i = 1; i <= K; i++)
                {
                    if(!_bs.test(HashFunc(i, StrToHash(str))))
                    {
                        return false;
                    }
                }
                return true;
            }
    };
}
